package com.ikangtai.shecare.home.calendar;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.App;
import com.ikangtai.shecare.common.Constant;
import com.ikangtai.shecare.common.EnConstant;
import com.ikangtai.shecare.common.al.DayUnitDSOutput;
import com.ikangtai.shecare.common.util.DateUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * 日历gridview中的每一个item显示的textview
 *
 * @author Vincent Lee
 */
public class CalendarAdapter extends BaseAdapter {

    private List<DayState> dayStates;
    private List<DayState> medianDates;
    private List<DayState> finalDates;
    private List<DayState> preDates, curDates, aftDates;
    private List<DayState> preNDates, curNDates, aftNDates;

    private boolean isLeapyear = false; // 是否为闰年
    private int daysOfMonth = 0; // 某月的天数
    private int dayOfWeek = 0; // 具体某一天是星期几
    private int lastDaysOfMonth = 0; // 上一个月的总天数
    private Context context;
    private String[] dayNumber = new String[42];
    // 一个gridview中的日期存入此数组中
    // private static String week[] = {"周日","周一","周二","周三","周四","周五","周六"};
    private SpecialCalendar sc = null;
    private LunarCalendar lc = null;
    private Resources res = null;
    private Drawable drawable = null;
    private String currentYear = "";
    private String currentMonth = "";
    private String currentDay = "";

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
    private int currentFlag = -1; // 用于标记当天
    private int[] schDateTagFlag = null; // 存储当月所有的日程日期

    private String showYear = ""; // 用于在头部显示的年份
    private String showMonth = ""; // 用于在头部显示的月份
    private String animalsYear = "";
    private String leapMonth = ""; // 闰哪一个月
    private String cyclical = ""; // 天干地支
    // 系统当前时间
    private String sysDate = "";
    private String sys_year = "";
    private String sys_month = "";
    private String sys_day = "";

    private int clickTemp = -1;

    private int MonthDateSize;
    private String[] dayNumberagain = new String[42]; // 一个gridview中的日期存入此数组中


    public CalendarAdapter() {
        Date date = new Date();
        sysDate = sdf.format(date); // 当期日期
        sys_year = sysDate.split("-")[0];
        sys_month = sysDate.split("-")[1];
        sys_day = sysDate.split("-")[2];

    }

    public CalendarAdapter(Context context, Resources rs, int jumpMonth, int jumpYear, int year_c, int month_c, int day_c, List<DayState> mDayState) {
        this();
        finalDates = new ArrayList<>();
        medianDates = new ArrayList<>();
        this.context = context;
        sc = new SpecialCalendar();
        lc = new LunarCalendar();
        this.res = rs;
        dayStates = mDayState;
        int stepYear = year_c + jumpYear;
        int stepMonth = month_c + jumpMonth;
        if (stepMonth > 0) {
            // 往下一个月滑动
            if (stepMonth % 12 == 0) {
                stepYear = year_c + stepMonth / 12 - 1;
                stepMonth = 12;
            } else {
                stepYear = year_c + stepMonth / 12;
                stepMonth = stepMonth % 12;
            }
        } else {
            // 往上一个月滑动
            stepYear = year_c - 1 + stepMonth / 12;
            stepMonth = stepMonth % 12 + 12;
            if (stepMonth % 12 == 0) {
            }
        }
        currentYear = String.valueOf(stepYear); // 得到当前的年份
        currentMonth = String.valueOf(stepMonth); // 得到本月
        // （jumpMonth为滑动的次数，每滑动一次就增加一月或减一月）
        currentDay = String.valueOf(day_c); // 得到当前日期是哪天

        getCalendar(Integer.parseInt(currentYear), Integer.parseInt(currentMonth));

    }

    public CalendarAdapter(Context context, Resources rs, int year, int month, int day) {
        this();
        this.context = context;
        sc = new SpecialCalendar();
        lc = new LunarCalendar();
        this.res = rs;
        currentYear = String.valueOf(year);// 得到跳转到的年份
        currentMonth = String.valueOf(month); // 得到跳转到的月份
        currentDay = String.valueOf(day); // 得到跳转到的天
        getCalendar(Integer.parseInt(currentYear), Integer.parseInt(currentMonth));
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return dayNumber.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.calendar_item, null);
            holder = new ViewHolder();
            holder.re_text_circle = (RelativeLayout) convertView.findViewById(R.id.re_text_circle);
            holder.textView = (TextView) convertView.findViewById(R.id.tvtext);
            holder.tv_text_bottom = (TextView) convertView.findViewById(R.id.tv_text_bottom);
            holder.re_text = (RelativeLayout) convertView.findViewById(R.id.re_text);
            holder.item_fuck = (ImageView) convertView.findViewById(R.id.item_fuck);
            holder.item_today = (ImageView) convertView.findViewById(R.id.item_today);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String d = dayNumber[position].split("\\.")[0];

        String dv = dayNumber[position].split("\\.")[1];
        if (position < daysOfMonth + dayOfWeek && position >= dayOfWeek) {
            holder.textView.setTextColor(context.getResources().getColor(R.color.black));
            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.calendar_item_bottom));
            if (dayNumber[position].split("\\.").length > 2) {
                if (dayNumber[0].split("\\.").length > 3) {

                    for (int i = 0; i < daysOfMonth; i++) {
                        String state = dayNumber[position].split("\\.")[2];
                        String fuck = dayNumber[position].split("\\.")[3];

                        switch (Locale.getDefault().getLanguage()) {
                            case "zh":
                                if (App.status == 0) {
                                    switch (state) {
                                        case Constant.kMenstruation:
                                            holder.textView.setTextColor(Color.WHITE);
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_menstruation);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.white));

                                            long timeStamp = DateUtil.getStringToDateMM(dayNumber[position].split("\\.")[1] + " 12:00:00");


                                            if (App.DayUnitDSOutputMap.get(timeStamp).isConfrimOrForecast(App.status) == DayUnitDSOutput.PERIOD_CONFIRM_YJQ) {

                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            } else {
                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink_pre));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink_pre));
                                            }

                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.white));
                                            break;
                                        case Constant.kOvulationday:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_day);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_yellow));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_yellow));
                                            break;
                                        case Constant.kOvulation:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_period);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            break;
                                        case Constant.kOvulationout:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_period);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            break;
                                        default:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.black));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.calendar_item_bottom));
                                            break;

                                    }
                                } else {
                                    switch (state) {
                                        case Constant.kMenstruation:
                                            long timeStamp = DateUtil.getStringToDateMM(dayNumber[position].split("\\.")[1] + " 12:00:00");

                                            holder.textView.setTextColor(Color.WHITE);
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_menstruation);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.white));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.white));
                                            if (App.DayUnitDSOutputMap.get(timeStamp).isConfrimOrForecast(App.status) == DayUnitDSOutput.PERIOD_CONFIRM_YJQ) {

                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            } else {
                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink_pre));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink_pre));
                                            }

//                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            break;
                                        case Constant.kDangerous:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_period);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_red));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_red));
                                            break;
                                        case Constant.kFollicular_phase:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_period);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.text_black));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.gray));
                                            break;
                                        default:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_safe);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_blue));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_blue));
                                            break;
                                    }
                                }
                                break;
                            default:
                                if (App.status == 0) {
                                    switch (state) {
                                        case EnConstant.kMenstruation:
                                            holder.textView.setTextColor(Color.WHITE);
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_menstruation_en
                                            );
                                            long timeStamp = DateUtil.getStringToDateMM(dayNumber[position].split("\\.")[1] + " 12:00:00");

                                            holder.textView.setTextColor(context.getResources().getColor(R.color.white));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.white));
                                            if (App.DayUnitDSOutputMap.get(timeStamp).isConfrimOrForecast(App.status) == DayUnitDSOutput.PERIOD_CONFIRM_YJQ) {

                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            } else {
                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink_pre));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink_pre));
                                            }

//                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            break;
                                        case EnConstant.kOvulationday:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_day_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_yellow));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_yellow));
                                            break;
                                        case EnConstant.kOvulation:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_period_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            break;
                                        case EnConstant.kOvulationout:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_ovulatory_period_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_green));
                                            break;
                                        default:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.black));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.calendar_item_bottom));
                                            break;

                                    }
                                } else {
                                    switch (state) {
                                        case EnConstant.kMenstruation:
                                            holder.textView.setTextColor(Color.WHITE);
                                            long timeStamp = DateUtil.getStringToDateMM(dayNumber[position].split("\\.")[1] + " 12:00:00");

                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_menstruation_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.white));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.white));
                                            if (App.DayUnitDSOutputMap.get(timeStamp).isConfrimOrForecast(App.status) == DayUnitDSOutput.PERIOD_CONFIRM_YJQ) {

                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            } else {
                                                holder.re_text.setBackground(context.getResources().getDrawable(R.drawable.circle_bg_pink_pre));
                                                holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink_pre));
                                            }

                                            //  holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_pink));
                                            break;
                                        case EnConstant.kDangerous:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_dangerous_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_red));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_red));
                                            break;

                                        case EnConstant.kFollicular_phase:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_dangerous);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.text_black));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.gray));
                                            break;
                                        default:
                                            holder.item_today.setImageResource(R.drawable.calendar_today_icon_safe_en);
                                            holder.textView.setTextColor(context.getResources().getColor(R.color.circle_bg_bottel_green));
                                            holder.tv_text_bottom.setTextColor(context.getResources().getColor(R.color.circle_bg_bottel_green));
                                            break;
                                    }
                                }


                        }
                        if (!fuck.equals(false + "")) {
                            holder.item_fuck.setVisibility(View.VISIBLE);
                        }
                    }

                }

            }


        }
        holder.textView.setText(d);
        holder.tv_text_bottom.setText(dv);
        if (currentFlag == position) {
            // 设置当天的背景
//          drawable = res.getDrawable(R.drawable.calendar_item_selected_bg);
            holder.item_today.setVisibility(View.VISIBLE);
        }

        if (clickTemp == position) {
            holder.re_text_circle.setVisibility(View.VISIBLE);
        } else {
            holder.re_text_circle.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }


    public void setSeclection(int position) {
        clickTemp = position;
    }

    // 得到某年的某月的天数且这月的第一天是星期几
    public void getCalendar(int year, int month) {
        isLeapyear = sc.isLeapYear(year); // 是否为闰年
        daysOfMonth = sc.getDaysOfMonth(isLeapyear, month); // 某月的总天数
        dayOfWeek = sc.getWeekdayOfMonth(year, month); // 某月第一天为星期几
        lastDaysOfMonth = sc.getDaysOfMonth(isLeapyear, month - 1); // 上一个月的总天数
        getWeek(year, month);

    }

    private List<DayState> getMonth(int month, int year) {
        int day;
        for (int i = 0; i < dayStates.size(); i++) {
            if ((dayStates.get(i).getDay() != null)) {
                if ((dayStates.get(i).getDay().split("-")[1]).equals(month + "") &&

                        dayStates.get(i).getDay().split("-")[0].equals(year + "")) {

                    medianDates.add(dayStates.get(i));
                }
            }
        }

        // 去重
        if (medianDates.size() > 0) {
            for (int i = 0; i < medianDates.size() - 1; i++) {
                for (int j = medianDates.size() - 1; j > i; j--) {
                    if (medianDates.get(j).equals(medianDates.get(i))) {
                        medianDates.remove(j);
                    }
                }
            }
        }

        //处理非标准月的数据
        if (medianDates.size() != 0) {
            day = daysOfMonth - Integer.valueOf(medianDates.get(0).getDay().split("-")[2]);
            if (medianDates.size() != daysOfMonth && (Integer.valueOf(medianDates.get(0).getDay().split("-")[2]) != 1)) {
                finalDates.clear();
                for (int p = 0; p < daysOfMonth - medianDates.size(); p++) {
                    //加在前面
                    switch (Locale.getDefault().getLanguage()) {
                        case "zh":
                            finalDates.add(new DayState("2000-0-0", Constant.kFollicular_phase, false));
                            break;
                        default:
                            finalDates.add(new DayState("2000-0-0", EnConstant.kFollicular_phase, false));

                    }
                }
                finalDates.addAll(medianDates);
                return finalDates;


            } else if (medianDates.size() != daysOfMonth) {
                finalDates.clear();
                //加在后面
                finalDates.addAll(medianDates);
                for (int p = 0; p < day; p++) {
                    switch (Locale.getDefault().getLanguage()) {
                        case "zh":
                            finalDates.add(medianDates.size() + p, new DayState("2000-0-0", Constant.kFollicular_phase, false));
                        default:
                            finalDates.add(medianDates.size() + p, new DayState("2000-0-0", EnConstant.kFollicular_phase, false));

                    }
                }
                return finalDates;

            }
            finalDates.clear();
            finalDates.addAll(medianDates);
        }
        if (finalDates.size() > 0) {
            MonthDateSize = finalDates.size();
            return finalDates;
        } else {
            return null;
        }

    }

    // 将一个月中的每一天的值添加入数组dayNuber中

    private void getWeek(int year, int month) {
        int j = 1;
        int flag = 0;
        String lunarDay = "";
        // 得到当前月的所有日程日期(这些日期需要标记)

        if (getMonth(month, year) != null) {
            if (preDates == null || preDates != null && !preDates.get(0).getDay().split("-")[1].equals(month + "")) {
                preDates = getMonth(month, year);
            }
            if (curDates == null || curDates != null && !curDates.get(0).getDay().split("-")[1].equals(month + "")) {
                curDates = getMonth(month, year);
            }
            if (aftDates == null || aftDates != null && !aftDates.get(0).getDay().split("-")[1].equals(month + "")) {
                aftDates = getMonth(month, year);
            }
            for (int i = 0; i < dayNumber.length; i++) {
                if (i < dayOfWeek) { // 前一个月

                    int temp = lastDaysOfMonth - dayOfWeek + 1;
                    lunarDay = lc.getLunarDate(year, month - 1, temp + i + 1, false);
                    dayNumber[i] = (temp + i) + "." + "aaa" + "." + preDates.get(i).getState() + "." + finalDates.get(i).isFuck();

                } else if (i < daysOfMonth + dayOfWeek) { // 本月

                    String day = String.valueOf(i - dayOfWeek + 1); // 得到的日期
                    lunarDay = lc.getLunarDate(year, month, i - dayOfWeek + 2, false);
                    dayNumber[i] = i - dayOfWeek + 1 + "." + curDates.get(i - dayOfWeek).getDay() + "." + curDates.get(i - dayOfWeek).getState() + "." + finalDates.get(i - dayOfWeek).isFuck();
                    if (sys_year.equals(String.valueOf(year)) && sys_month.equals(String.valueOf(month)) && sys_day.equals(day)) {
                        // 标记当前日期
                        currentFlag = i;
                    }
                    setShowYear(String.valueOf(year));
                    setShowMonth(String.valueOf(month));
                    setAnimalsYear(lc.animalsYear(year));
                    setLeapMonth(lc.leapMonth == 0 ? "" : String.valueOf(lc.leapMonth));
                    setCyclical(lc.cyclical(year));
                } else { // 下一个月


                    lunarDay = lc.getLunarDate(year, month + 1, j + 1, false);
                    dayNumber[i] = j + "." + "aa" + "." + aftDates.get(i - daysOfMonth - dayOfWeek).getState() + "." + finalDates.get(i - daysOfMonth - dayOfWeek).isFuck();
                    j++;
                }
            }
        } else {
            if (preNDates == null || preNDates != null && !preNDates.get(0).getDay().split("-")[1].equals(month + "")) {
                preNDates = getMonth(month, year);
            }
            if (curNDates == null || curNDates != null && !curNDates.get(0).getDay().split("-")[1].equals(month + "")) {
                curNDates = getMonth(month, year);
            }
            if (aftNDates == null || aftNDates != null && !aftNDates.get(0).getDay().split("-")[1].equals(month + "")) {
                aftNDates = getMonth(month, year);
            }
            for (int i = 0; i < dayNumber.length; i++) {
                if (i < dayOfWeek) { // 前一个月

                    int temp = lastDaysOfMonth - dayOfWeek + 1;
                    lunarDay = lc.getLunarDate(year, month - 1, temp + i, false);
                    if (getMonth(month, year) != null) {
                        dayNumber[i] = (temp + i) + "." + "aa" + "." + preNDates.get(i).getState() + "." + finalDates.get(i).isFuck();
                    } else {
                        dayNumber[i] = (temp + i) + "." + "aa";
                    }

                } else if (i < daysOfMonth + dayOfWeek) { // 本月


                    String day = String.valueOf(i - dayOfWeek + 1); // 得到的日期
                    lunarDay = lc.getLunarDate(year, month, i - dayOfWeek + 1, false);
                    if (getMonth(month, year) != null) {
                        dayNumber[i] = i - dayOfWeek + 1 + "." + curNDates.get(i - dayOfWeek + 1).getDay() + "." + curNDates.get(i - dayOfWeek).getState() + "." + finalDates.get(i - dayOfWeek).isFuck();
                    } else {
                        dayNumber[i] = i - dayOfWeek + 1 + "." +"aa";
                    }

//                    dayNumber[i] = i - dayOfWeek + 1 + "." + lunarDay;
                    // 对于当前月才去标记当前日期
                    if (sys_year.equals(String.valueOf(year)) && sys_month.equals(String.valueOf(month)) && sys_day.equals(day)) {
                        // 标记当前日期
                        currentFlag = i;
                    }
                    setShowYear(String.valueOf(year));
                    setShowMonth(String.valueOf(month));
                    setAnimalsYear(lc.animalsYear(year));
                    setLeapMonth(lc.leapMonth == 0 ? "" : String.valueOf(lc.leapMonth));
                    setCyclical(lc.cyclical(year));
                } else { // 下一个月
                    lunarDay = lc.getLunarDate(year, month + 1, j, false);

                    if (getMonth(month, year) != null) {
                        dayNumber[i] = j + "." + "aa" + "." + aftNDates.get(i - dayOfWeek).getState() + "." + finalDates.get(i - dayOfWeek).isFuck();
                    } else {
                        dayNumber[i] = j + "." + "aa";
                    }
                    j++;
                }
            }
        }
    }


    static class ViewHolder {
        RelativeLayout re_text_circle;
        TextView textView;
        TextView tv_text_bottom;
        RelativeLayout re_text;
        ImageView item_fuck;
        ImageView item_today;

    }

    public void matchScheduleDate(int year, int month, int day) {

    }

    /**
     * 点击每一个item时返回item中的日期
     *
     * @param position
     * @return
     */
    public String getDateByClickItem(int position) {
        return dayNumber[position];
    }

    /**
     * 在点击gridView时，得到这个月中第一天的位置
     *
     * @return
     */
    public int getStartPositon() {
        return dayOfWeek + 7;
    }

    /**
     * 在点击gridView时，得到这个月中最后一天的位置
     *
     * @return
     */
    public int getEndPosition() {
        return (dayOfWeek + daysOfMonth + 7) - 1;
    }

    public String getShowYear() {
        return showYear;
    }

    public void setShowYear(String showYear) {
        this.showYear = showYear;
    }

    public String getShowMonth() {
        return showMonth;
    }

    public String getShowMonthChina() {
        switch (showMonth) {
            case "1":
                return context.getString(R.string.december);
            case "2":
                return context.getString(R.string.January);
            case "3":
                return context.getString(R.string.February);
            case "4":
                return context.getString(R.string.March);
            case "5":
                return context.getString(R.string.April);
            case "6":
                return context.getString(R.string.May);
            case "7":
                return context.getString(R.string.June);
            case "8":
                return context.getString(R.string.July);
            case "9":
                return context.getString(R.string.August);
            case "10":
                return context.getString(R.string.September);
            case "11":
                return context.getString(R.string.October);
            default:
                return context.getString(R.string.November);
        }

    }

    public void setShowMonth(String showMonth) {
        this.showMonth = showMonth;
    }

    public String getAnimalsYear() {
        return animalsYear;
    }

    public void setAnimalsYear(String animalsYear) {
        this.animalsYear = animalsYear;
    }

    public String getLeapMonth() {
        return leapMonth;
    }

    public void setLeapMonth(String leapMonth) {
        this.leapMonth = leapMonth;
    }

    public String getCyclical() {
        return cyclical;
    }

    public void setCyclical(String cyclical) {
        this.cyclical = cyclical;
    }
}
